import { ComponentType } from "./componentType";
import { isFunction } from "@/utils/common";
import { Slots } from "vue";

/**
 * @description: 生成placeholder
 */
export function createPlaceholderMessage(component: ComponentType) {
    if (!component) return;
    if (component.includes("RangePicker")) {
        return "请选择";
    }
    if (component.includes("Input") || component.includes("Complete") || component.includes("Rate")) {
        return "请输入";
    } else {
        return "请选择";
    }
}
export function getSlot(slots: Slots, slot = "default", data?: any) {
    if (!slots || !Reflect.has(slots, slot)) {
        return null;
    }
    if (!isFunction(slots[slot])) {
        console.error(`${slot} is not a function!`);
        return null;
    }
    const slotFn = slots[slot];
    if (!slotFn) return null;
    return slotFn(data);
}
/**
 * extends slots
 * @param slots
 * @param excludeKeys
 */
export function extendSlots(slots: Slots, excludeKeys: string[] = []) {
    const slotKeys = Object.keys(slots);
    const ret: any = {};
    slotKeys.map((key) => {
        if (excludeKeys.includes(key)) {
            return null;
        }
        ret[key] = (data?: any) => getSlot(slots, key, data);
    });
    return ret;
}
